<!DOCTYPE html>
<html class="iframe-h" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}"/>
		<link rel="stylesheet" type="text/css" th:href="@{/css/admin.css}"/>
		<link th:href="@{/lib/bootstraps/css/bootstrap.css}" rel="stylesheet" />
	</head>

	<body>
		<div class="wrap-container clearfix">
			<div class="column-content-detail">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-inline tool-btn">
							<button class="layui-btn layui-btn-small layui-btn-normal addText" data-url="/toAddPic"><i class="layui-icon">&#xe654;</i></button>
							<button class="layui-btn layui-btn-small layui-btn-danger remove"  data-url="/removePic"><i class="layui-icon">&#xe640;</i></button>
							<button class="layui-btn layui-btn-small ayui-btn-normal modify"  data-url="/toModifyTextData"><i class="layui-icon">&#xe614;</i></button>
						</div>
						<!--<div class="layui-inline">
							<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
						</div>-->

						<!--<button class="layui-btn layui-btn-normal" lay-submit="search">搜索</button>-->
					</div>
				</form>
				<table class="layui-table" lay-data="{height: 'full', cellMinWidth: 80,  limit:15,limits:[15,30],
					url:'/pics', page:true, id:'test'}" lay-filter="test" id="test">
					<thead>
					<tr>
						<th lay-data="{type:'checkbox'}">ID</th>
						<th lay-data="{field:'name',align:'center'}">名称</th>
						<th lay-data="{field:'picType', align:'center'}">图片分类</th>
						<th lay-data="{field:'picSort', align:'center'}">排序</th>
						<th lay-data="{field:'turnUrl', align:'center'}">跳转链接</th>
						<th lay-data="{field:'view', align:'center',templet: '#wenzhang',event: 'viewText'}">内容</th>
						<th lay-data="{field:'createTime', align:'center',templet:'#timeFormat'}">创建时间</th>
					</tr>
					</thead>
				</table>
			</div>
		</div>


		<script th:src="@{/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
		<script th:src="@{/js/common.js}" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" th:src="@{/lib/bootstraps/js/jquery-3.2.1.min.js}"></script>
		<script type="text/javascript" th:src="@{/lib/bootstraps/js/bootstrap.js}"></script>
		<script type="text/javascript" th:src="@{/js/basic/dateutil.js}"></script>
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-sm" lay-event="execute">执行</a>
			{{#  if(d.triggerState == "ACQUIRED" || d.triggerState == "WAITING"){ }}
				<a class="layui-btn layui-btn-warm layui-btn-sm" lay-event="stop">停止</a>
			{{#  }else if(d.triggerState == "PAUSED"){ }}
				<a class="layui-btn layui-btn-warm layui-btn-sm" lay-event="resume">恢复</a>
			{{#  }}}

		</script>
		<script type="text/html" id="wenzhang">
			<button class="layui-btn layui-btn-primary layui-btn-sm">点击查看</button>
		</script>
		<script type="text/html" id="timeFormat">
			{{getFormatDateByLong(d.createTime,'yyyy-MM-dd hh:mm:ss') }}
		</script>
		<script>

            $(function () {


                $('#modifyTask').on('hide.bs.modal', function () {
                    $('#actAdd')[0].reset();
                });


            });

            layui.config({
                base: '/js/module/'
            }).extend({
                dialog: 'dialog',
            });

			layui.use(['table','tree','jquery','dialog'], function() {
				var table = layui.table,
					form = layui.form,
                    $ = layui.jquery,
					tree = layui.tree,
                    dialog = layui.dialog;

                //获取当前iframe的name值
                var iframeObj = $(window.frameElement).attr('name');

				table.on('tool(test)', function(obj){
                    var data = obj.data;
                    if(obj.event === 'viewText'){
                        layer.open({
                            type: 1,
                            title: '预览图片',
                            /*closeBtn: 0,*/
                            area: ['80%', '80%'],
                            //skin: 'layui-layer-nobg', //没有背景色
                            shadeClose: false,
                            content: '<img src='+data.picUrl+'>'
                        });
                    }
				});

                $('.addText').click(function() {
                    let url=$(this).attr('data-url');
                    //将iframeObj传递给父级窗口,执行操作完成刷新
                    page("新增图片", url, iframeObj, w = '80%', h = '80%');
                    return false;

                }).mouseenter(function() {

                    dialog.tips('新增图片', '.addText');

                });



                $('.remove').click(function() {
                    var checkStatus = table.checkStatus('test'),data = checkStatus.data;
                    if(data.length<1){
                        layer.msg("请选择一条记录")
                        return false;
                    }
                    if(data.length>1){
                        layer.msg("只能选择一条记录")
                        return false;
                    }
                    let url=$(this).attr('data-url');
                    if(data[0].triggerState == "ACQUIRED" || data[0].triggerState == "WAITING"){
                        layer.msg("运行中的任务不可删除！");
                        return false;
                    }
                    layer.confirm( '您确定要删除选中项',function(index){
                        let dataForm = {
                            time:(new Date()).toString(),
                            id:data[0].id
                        };
						$.ajax({
							url:url,
							data:dataForm,
							type: 'post',
							dataType:'json',
							success:function (data){
								if(data.code === 200){
									layer.close(index);
									layer.msg("删除成功");
									table.reload('test',{page:{curr:1}});
								}else{
                                    layer.msg(data.msg);
								}
							}
						});
                    });
                    return false;

                }).mouseenter(function() {
                    dialog.tips('删除', '.remove');
                })
            });


            $("#actAdd").bind("submit",function(){
                let data = {
                    jobName:$('#jobName').val(),
                    jobGroup:$('#jobGroup').val(),
                    description:$('#description').val(),
                    jobClassName: $("#jobClassName").val(),
                    cronExpression: $("#cronExpression").val(),
                    oldJobName: $("#oldJobName").val(),
                	oldJobGroup: $("#oldJobGroup").val()
                }

                $.ajax({
                    url: '/addTask',
                    data: data,
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.data == true) {
                            layer.msg('修改成功');
                            $("#modifyTask").modal('hide');
                            layui.table.reload('test',{page:{curr:1}});
                        } else {
                            layer.msg('修改失败，请刷新页面');
                        }
                    }
                });
                return false;
            });

		</script>
	</body>

</html>